package cn.software.service.impl;

import cn.software.entity.Class;
import cn.software.entity.Subject;
import cn.software.entity.param.ClassParam;
import cn.software.entity.param.SubjectParam;
import cn.software.entity.vo.ClassVo;
import cn.software.entity.vo.InvCodeVo;
import cn.software.entity.vo.SubjectVo;
import cn.software.mapper.ClassMapper;
import cn.software.service.ClassService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ClassServiceImpl implements ClassService {

    @Autowired
    private ClassMapper classMapper;


    @Override
    public boolean addClass(ClassParam classParam) {
        Class myclass=transformClassParamToClass(classParam);
        int insert=classMapper.insert(myclass);
        return insert>0;
    }

    @Override
    public boolean updateClass(ClassParam classParam) {
        Class myclass=transformClassParamToClass(classParam);
        int update=classMapper.updateById(myclass);
        return update>0;
    }

    @Override
    public boolean deleteClass(ClassParam classParam) {
        Class myclass=transformClassParamToClass(classParam);
        myclass.setIsDeleted(1);
        int update=classMapper.updateById(myclass);
        return update>0;
    }

    @Override
    public List<ClassVo> getAllClass() {
        List<ClassVo> voList=new ArrayList<>();
        //xml
        voList=classMapper.getAllClass();
        return voList;
    }

    @Override
    public ClassVo getClassById(Integer id) {
        ClassVo classVo = classMapper.getClassById(id);
        if(classVo == null || classVo.getIsDeleted() == 1) {
            return null;
        }
        return classVo;
    }


    @Override
    public List<ClassVo> getClassByStuId(Integer id) {

        List<ClassVo> classVoList = classMapper.getClassByStuId(id);
        return classVoList;
    }

    @Override
    public InvCodeVo getInvCode(Integer id) {
        InvCodeVo invCodeVo=classMapper.getInvCode(id);
        return invCodeVo;
    }


    //没用
    private ClassVo transformClassToVo(Class myclass) {
        ClassVo classVo=new ClassVo();
        BeanUtils.copyProperties(myclass,classVo);
        return classVo;
    }

    private Class transformClassParamToClass(ClassParam classParam) {
        Class myclass=new Class();
        BeanUtils.copyProperties(classParam,myclass);
        return myclass;
    }


}
